package com.company.management.controller.reward;


import com.company.management.service.reward.SysFileService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 文件信息操作处理
 *
 */
@RestController
@RequestMapping("/api/file")
public class FileInfoController {

    @Resource
    private SysFileService sysFileService;

    @PostMapping("/upload")
    public ResponseEntity<String> upload(@RequestParam(value = "file") MultipartFile file) {
        if (file.isEmpty()) {
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("No file uploaded.");
        }
        String id = sysFileService.uploadFile(file);
        return new ResponseEntity<>(id,HttpStatus.OK);
    }

    @GetMapping("/download")
    public ResponseEntity<Boolean> download(@RequestParam("fileId") String fileId, HttpServletResponse response) {
        sysFileService.downloadFile(fileId, response);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
